package hl.action;

import org.apache.struts2.convention.annotation.Action;
import org.apache.struts2.convention.annotation.Namespace;
import org.springframework.beans.factory.annotation.Autowired;

import com.opensymphony.xwork2.ModelDriven;

import hl.pageModel.DataGrid;
import hl.pageModel.Json;
import hl.pageModel.Place;
import hl.service.PlaceService;

@Namespace("/")
@Action(value = "placeAction")
public class PlaceAction extends BaseAction implements ModelDriven<Place> {

	Place place = new Place();

	private PlaceService placeService;

	@Override
	public Place getModel() {
		return place;
	}

	public PlaceService getPlaceService() {
		return placeService;
	}

	@Autowired
	public void setPlaceService(PlaceService placeService) {
		this.placeService = placeService;
	}

	public void add() {
		Json j = new Json();
		try {
			placeService.save(place);
			j.setSuccess(true);
			j.setMsg("保存成功");

		} catch (Exception e) {
			j.setMsg(e.getMessage());
		}
		super.writeJson(j);
	}

	public void getDatagrid() {
		DataGrid d = placeService.getDatagrid(place);
		super.writeJson(d);
	}

	public void edit() {
		Json j = new Json();
		try {
			placeService.edit(place);
			j.setSuccess(true);
			j.setMsg("修改成功！");

		} catch (Exception e) {
			j.setMsg(e.getMessage());
		}
		super.writeJson(j);
	}

	public void remove() {
		Json j = new Json();
		try {
			placeService.remove(place);
			j.setSuccess(true);
			j.setMsg("删除成功！");

		} catch (Exception e) {
			j.setMsg(e.getMessage());
		}
		super.writeJson(j);
	}
	
	public void getComboBox() {
		super.writeJson(placeService.getComboBox(place));
	}
}
